#include <unistd.h>

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ncurses.h> 
#include <common.h>

#include "PosixTestClient.h"
#include "parser.h"
#include "ClientConnect.h"

const unsigned MAX_ATTEMPTS = 50;
const unsigned SLEEP_TIME = 10;

int main(int argc, char** argv)
{
	//const char* host = argc > 1 ? argv[1] : "";
	//unsigned int port = 7496;
	//int clientId = 0;
	
	cmd_parser parser;
        client = new PosixTestClient; // global var
  
	WINDOW* scr = initscr ();
	noecho ();
  //cbreak();
	keypad (scr, TRUE);
	nodelay(scr, TRUE);
	scrollok(scr, TRUE);
	idlok(scr, TRUE);	

	printw ("ECE358 Foundations of Computing\nFinal Project 2012\n\n");
	printw (CMD_LINE);

	int res;
	//int s, i;
	//char c;

  	for (;;) {
		res = parser.cmd_getch(scr);
		
		if (res == -1)
			break;

/*
		if (time(NULL) - s > 0) {
			s = time(NULL);
			printw ("%d\n", i);
			i++;
		}

		c = getch();
		if (c == '\n') {
			printw ("connecting...\n");
			client->connect ("", 7496, 0);
			if (client->isConnected())
				printw ("Connection Successful.\n");
			else 
				printw ("Connection Failed.\n");
    		}
		else if (c == 'q')
			break;
*/
  	}
	endwin ();
	return 0;   
}
    /*
	for (;;) {
		++attempt;
		printf( "Attempt %u of %u\n", attempt, MAX_ATTEMPTS);

		PosixTestClient client;

		client.connect( host, port, clientId);

		while( client.isConnected()) {
			client.processMessages();
		}

		if( attempt >= MAX_ATTEMPTS) {
			break;
		}

		printf( "Sleeping %u seconds before next attempt\n", SLEEP_TIME);
		sleep( SLEEP_TIME);
	}
*/

